require "Reward"

QNW_TS_ItemReward = QNW_TS_Reward:derive("QNW_TS_ItemReward")

function QNW_TS_ItemReward:new(_item, _num)
    local o = QNW_TS_Reward:new()
    setmetatable(o, self)
    self.__index = self

    o.num = _num
    o.item = _item

    return o
end

function QNW_TS_ItemReward:getText()
    local item = InventoryItemFactory.CreateItem(self.item)
    return item:getDisplayName() .. "+" .. self.num
end

function QNW_TS_ItemReward:apply()
    local inventory = getPlayer():getInventory()
    for i = 1, self.num do
        inventory:AddItem(self.item)
    end
end

function QNW_TS_ItemReward:save()
    return { Type = self.Type, item = self.item, num = self.num }
end

function QNW_TS_ItemReward:load(_table)
    self.num = _table.num
    self.item = _table.item
end